#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
int main(int argc)
{
Mat img = imread("kuang1.jpg"); //读入图像,RGB三通道
resize(img, img, Size(img.cols / 7, img.rows / 7), 0, 0, INTER_LINEAR);
imshow("原图像", img);
Mat res; //分割后图像
int spatialRad = 20; //空间窗口大小
int colorRad = 20; //色彩窗口大小
int maxPyrLevel = 3; //金字塔层数
pyrMeanShiftFiltering(img, res, spatialRad, colorRad, maxPyrLevel); //色彩聚类平滑滤波
imshow("res", res);
imwrite("pyrMeanShiftFiltering_RGB.jpg",res);
Mat img_hsv,res_hsv;
cvtColor(img, img_hsv, CV_BGR2HSV);
pyrMeanShiftFiltering(img_hsv, res_hsv, spatialRad, colorRad, maxPyrLevel);
imshow("res_hsv", res_hsv);
imwrite("pyrMeanShiftFiltering_HSV.jpg",res_hsv);
waitKey();
return 0;
}